package com.tl.Hw02;

import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

/**
 * 使用注解的方式
 */
@WebServlet(name = "hw02", value = "/test")
public class Hw02 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //获取页面url中的参数并回显在页面上
        String name  = req.getParameter("name");
        String age = req.getParameter("age");
        String classNo = req.getParameter("classNo");

        //在控制台显示 
        System.out.println("name-->"+name);
        System.out.println("age-->"+age);
        System.out.println("classNo-->"+classNo);

        //在页面显示
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        writer.println("姓名-->"+name);
        writer.println("年龄-->"+age);
        writer.println("班级-->"+classNo);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}